package gui;
//imports
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import domein.Functies;


public class LoginJPanel extends javax.swing.JPanel {
	private JLabel lblLogin;
	private JLabel lblPaswoord;
	private JPasswordField pwdPaswoord;
	private JButton cmdLogin;
	private JButton cmdReset;
	private JLabel lblSign_in;
	private JTextField txtLogin;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	
	public LoginJPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(361, 169));
			this.setLayout(null);
			{
				lblLogin=Functies.makeLabel (lblLogin,"login:",18,52,75,14 );
				this.add(lblLogin);
			}
			{
				lblPaswoord=Functies.makeLabel (lblPaswoord,"Paswoord:",18,78,83,14);
				this.add(lblPaswoord);
			}
			{
				txtLogin = Functies.makeText (txtLogin,"",105,49,165,21);
				this.add(txtLogin);
			}
			{
				pwdPaswoord = Functies.makePwd (pwdPaswoord,"",105,76,165,21);
				this.add(pwdPaswoord);
			}
			{
				
				lblSign_in = Functies.makeLabel (lblSign_in,"Meld u aan met uw gebruikersnaam en wachtwoord",18,12,331,14);
				this.add(lblSign_in);
				lblSign_in.setForeground(new java.awt.Color(0,0,160));
				lblSign_in.setFont(new java.awt.Font("Tahoma",1,11));
			}
			{
				cmdLogin = Functies.makeButton(cmdLogin,"Login",142,118,85,33);
				this.add(cmdLogin);
				cmdLogin.setBounds(180, 118, 85, 33);
				cmdLogin.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						LoginActionPerformed(evt);
					}
				});
			}
			{
				cmdReset = Functies.makeButton(cmdReset,"reset",70,118,85,33);
				this.add(cmdReset);
				cmdReset.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ResetActionPerformed(evt);
					}
				});
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

//	Button Actions
	private void LoginActionPerformed(ActionEvent evt) {

		login();
		
	}//end LoginActionPerformed
	
	private void ResetActionPerformed(ActionEvent evt) {
		
		reset();
		
	}//end ResetActionPerformed
	
//Functions	
	
	private void reset(){

		pwdPaswoord.setText("");
		txtLogin.setText("");
		
	}//end reset
	
	private boolean loginCorrect(){
		
		boolean correct = false;
		String login = txtLogin.getText();
		String paswoord=String.valueOf(pwdPaswoord.getPassword());
		/**
		 *Login zoeken in de database
		 *Als login bestaat kijken of paswoord klopt
		 */
		
		return correct;
	}//end logincorrect
	
	private void login(){
		/**
		 *Login gegevens verwerken.
		 *bij foute login de velden terug leegmaken
		 *Als login correct is status van gebruiker controleren (admin of medewerker)
		 *Als gebruiker == medewerker => Toon reservatie scherm 
		 *Als gebruiker == administrator => Vraag:( personeeksbeheer of reservatiebeheer)
		 *Toon het gewenste scherm
		 *Sluit huidig scherm
		 */
		if (loginCorrect()==true){
			
		}else{
			JOptionPane.showMessageDialog(null,"Ongeldige login of paswoord!");
			reset();			
		}
	}//end Login
	
	
	

}
